package com.gugee.ins.common.dal.mapper.blogger;

import com.gugee.ins.common.model.mysql.blogger.InsBloggerMain;
import com.gugee.ins.common.model.mysql.blogger.InsBloggerRelation;
import com.gugee.ins.data.common.msg.InsBloggerMessage;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: luolifeng
 * Date: 2021-03-15 9:32
 */
public interface InsBloggerRelationExtMapper  extends InsBloggerRelationMapper {

    @Insert("<script>" +
            "insert into ins_blogger_relation " +
            "(uid,is_merchant,is_tagged_by_media,is_active_follower,is_sponsor,is_has_merchant_media,create_time) " +
            "values " +
            "<foreach item=\"relations\" collection=\"relations\"  separator=\",\" >" +
            "(#{relations.uid},#{relations.isMerchant},#{relations.isTaggedByMedia},#{relations.isActiveFollower},#{relations.isSponsor},#{relations.isHasMerchantMedia},#{relations.createTime})" +
            "</foreach>" +
            "</script>")
    int batchInsert(List<InsBloggerRelation> relations) ;

    /**
     * 满足时间范围内，未被爬取uid的播主列表
     * @param startTime
     * @param endTime
     * @return 播主列表
     */
    @Select( " SELECT uid FROM ins_blogger_relation a WHERE a.create_time BETWEEN #{startTime} AND #{endTime}  AND  EXISTS (select b.id from ins_blogger b where b.uid =a.uid AND b.account_status=0 AND b.last_collect_time=0)" )
    List<InsBloggerMessage> produceMsgFromBloggerRelation(long startTime, long endTime);

}
